'use strict';
/**
 * Created by FreezeSoul on 2015/9/30.
 */
define([
        'angular',
        'adConfig',
        'app/modules/page/define',
        'app/modules/page/services/page'
    ],
    function (angular, adConfig) {
        angular.module('ad.page')
            .controller('adPageAddController', ['$scope', '$uibModalInstance', 'adPageEditService', 'item', function ($scope, $uibModalInstance, service, item) {
                $scope.item = {
                    page_id: -1,
                    page_name: '',
                    page_data: '',
                    page_home: 0,
                    page_folder_id: item.data.folder_id,
                    page_version: 0,
                    page_type_id: 'free',
                    page_home_bool: false
                };

                $scope.layoutTypes = adConfig.layoutTypes;

                $scope.ok = function () {
                    $scope.item.page_home = $scope.item.page_home_bool ? 1 : 0;
                    service.addPage($scope.item).then(function (data) {
                        $uibModalInstance.close(data);
                    });
                };

                $scope.cancel = function () {
                    $uibModalInstance.dismiss('cancel');
                };
            }]);
    });